package com.zone.editor.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author: pkqlqx
 * @CreateDate: 2021/12/17 9:54
 * @Description:
 */
public class AssetUtil {

    public static Bitmap getAsset(Context context, String fileName){
        InputStream is = null;
        Bitmap b5 = null;

        try {
            AssetManager assetManager = context.getAssets();
            is=assetManager.open(fileName);    //直接写assets文件夹下的图片名就可以
            b5 = BitmapFactory.decodeStream(is);
            if(b5 != null && !b5.isRecycled()){
                System.out.println("bitmap  ok!!!!!!!!!!!!!!");
            }
        }
        catch (IOException e){
            e.printStackTrace();
        } finally {
            if (is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return b5;
    }

}
